/********************************************************
/* Inclusions */

#include <P18F452.h>
#include <adc.h>
#include <stdio.h>
#include <usart.h>
#include <stdlib.h>
#include <delays.h>
#include <string.h>

/********************************************************
/* CONSTANTS */

#define SPBRGSET	0b00011001
#define	BUFFSIZE_IR	50
#define LF	0x0A
#define CR	0x0D


#pragma code 



/********************************************************
/* FUNCTIONS */

/**
* @brief setup_IR
* @param none
* @return none
* @detail function used to set-up ADC and UART hardware
* to test Infrared Sensor
*/

void setup_IR(void);

/** 
* @brief get_IR 
* @param none
* @return voltage - average voltage value from IR sensor
* @details The function fills up the Infrared dedicated buffer with values from ADC and 
* then calculates and returns their mean value.
* @note buffer and its size are determined by global variabled buffer_IR[] and BUFFSIZE_IR
* respectively.
* @todo nothing, I hope
* @author Gennady Bolotov
*/

unsigned int get_IR(void);

/**
* @brief send_in
* @param data - data to be sent.
* @return none
* @details The function takes an integer value 'data', converts it into hex ASCII equivalent
* and sends it via UART to hyperterminal.
* @note Serial Transmitter must be configured before calling this function.
* @todo need to find a way to convert hex into decimal ASCII representation.
* @author Gennady Bolotov
*/

void send_int(unsigned int data);


/**
* @brief fetch_IR_dist
* @param address - address in the lookup table
* @return distance - distance in mm, read from lookup table
* @details The function reads the voltage read from IR sensor and converts it
* into equivalent address in the lookup table. It then takes the value stored in
* this address and returns the distance to object in mm.
* @note All values are in hex.
* @todo nothing, I hope
* @author Gennady Bolotov
*/

unsigned int fetch_IR_dist(unsigned int address);


